package com.itheima.service.db.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.BlackList;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.mapper.db.BlackListMapper;
import com.itheimma.service.db.BlackListService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListServiceImpl implements BlackListService {

    @Autowired
    private BlackListMapper blackListMapper;

    @Override
    public PageBeanVo findByPage(Long id, Integer pageNum, Integer pageSize) {
        //创建page，使用分页信息将他查询出来，查的是
        /*开启分页，分页查询，封装vo*/

        Page<BlackList> page = new Page<>(pageNum,pageSize);

        QueryWrapper<BlackList> qw = new QueryWrapper<>();
        qw.eq("user_id", id);
        page= blackListMapper.selectPage(page,qw);

        return new PageBeanVo(pageNum , pageSize , page.getTotal() ,page.getRecords());
    }

    @Override
    public void remove(Long id, Long blackUserId) {
        QueryWrapper<BlackList> qw = new QueryWrapper<>();
        qw.eq("user_id" ,id);
        qw.eq("black_user_id",blackUserId);
        blackListMapper.delete(qw);
    }
}
